<template>
	<view class="container">
		<view class="uni-card">
			<uni-card>
				
				<view class="form-view">
					<view style="text-align: center;background-color: aqua; margin-bottom: 10rpx;">登录页</view>
					<uni-forms-item label="账号:" name="username">
						<uni-easyinput type="text" v-model="admin.username" placeholder="请输入账号" />
					</uni-forms-item>
					<uni-forms-item label="密码:" name="pwd">
						<uni-easyinput type="password" v-model="admin.pwd"  placeholder="请输入密码" />
					</uni-forms-item>
					
					<button type="primary" @click="login(admin)" >登录</button>
				</view>
			</uni-card>
		</view>

	</view>
</template>

<script>
	import api from "../../api/api.js"
	export default {
		data() {
			return {
				admin: {
					username: '',
					pwd: ''
				}
			}
		},
		methods: {
			login(admin){
				// console.log(admin);
				// console.log("admin: " + JSON.stringify(admin));
				api.adminLogin(this.admin).then(res=>{
					if(res.code === 200 && res.data){
						uni.setStorage({
							key:api.base.userInfo,
							data:res.data
						})
						uni.navigateTo({
							url:"/pages/index/index"
						})
						// console.log("返回结果：",JSON.stringify(res.data));
					}else{
						uni.showToast({
							icon:'none',
							title:'请检查账号密码是否正常'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.uni-card {
		width: 40%;
		height: 600rpx;
		margin: 100rpx auto;
		display: flex;
		flex-direction: columnm;
		justify-content: center;
		align-items: center;
		// border: 1px rebeccapurple solid;
		background-color: #e2e2e2;
		.form-view{
			// border: 1px rebeccapurple solid;
			font-size: 30rpx;
			.uni-forms-item{
				font-size: 80rpx;
			}
		}
	}
</style>